Skip to content

refactor(pool): use sleep instead of sleep_until#233

Closed
dswij wants to merge 1 commit intohyperium:masterfrom
dswij:pool-timer-tokio
Closed

refactor(pool): use sleep instead of sleep_until#233
dswij wants to merge 1 commit intohyperium:masterfrom
dswij:pool-timer-tokio

Conversation

@dswij
Copy link
Copy Markdown
Member

@dswij dswij commented Sep 17, 2025

This PR refactors the usage of Timer::sleep_until with Timer::sleep.

sleep_until is a convenient method that is logically equivalent with sleep, but requires the use of std::time::Instant. This have some effect when downstream users rely on non-std Instant.

This commit refactors all usage of `Timer::sleep_until` with
`Timer::sleep`.

`sleep_until` is a convenient method that is logically equivalent with
`sleep`, but requires the use of `std::time::Instant`.  This have some effect when
downstream users rely on non-std `Instant`.
Comment thread src/client/legacy/pool.rs
}

let deadline = Instant::now() + self.duration;
self.timer.reset(&mut sleep, deadline);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call has the benefit of allowing implementors to reuse an allocated sleep, instead of allocating a new one...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. But I wonder if reuse instead of allocation has that much of an impact in practice.

@dswij dswij closed this Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants